package y23.Nov;

import java.io.*;
import java.util.Scanner;

public class Test5 {
    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要复制的文件：");
        String sourcePath = scanner.next();
        File f = new File(sourcePath);
        if(!f.exists()){
            System.out.println("文件不存在");
            return;
        }
        if (!f.isFile()){
            System.out.println("该文件不是普通文件");
        }
        System.out.println("请输入要复制到目标路径");
        String destPath = scanner.next();
        File destFile = new File(destPath);
        if (destFile.exists()){
            return;
        }
        try (InputStream is = new FileInputStream(f)){
            try (OutputStream os = new FileOutputStream(destFile)){
                byte[] b = new byte[1024];
                int n;
                while(true){
                    n = is.read(b);
                    if (n==1){
                        break;
                    }
                    os.write(b,0,n);
                }
                os.flush();
            }
        }

    }
}
